<template>
    <div >
        <van-nav-bar
        title="所有照片"
        right-text="下一步"
        left-arrow
        @click-left="onClickLeft"
        @click-right="onClickRight"
        style="--van-nav-bar-text-color: #FF8094;     --van-nav-bar-icon-color: none;"       
        />
    </div>

    <div class="photo">
        <div style="position: absolute;">
            <img :src="getAssetURL(aa)" alt="" style="width: 390px;height: 300px;">
        </div>
        <div @click="pho" v-if="bb" style="text-align: center; line-height: 300px; color: #FFFFFF; z-index: 999; position: absolute; margin: 0 auto; width: 390px;">相机照片</div>
        <div class="cover" v-if="bb"></div>
    </div>
    <div class="pic">
        <van-uploader :after-read="afterRead" style="--van-uploader-size: 85px; margin-top: 5px; margin-left: 5px;"  />
        

    <!-- <div class="pic">
        <el-upload
            name="file"
            :show-file-list="false"
            action="/upload"
        >
    </el-upload> -->
</div>
    



 
</template>

<script lang="ts">
import axios from 'axios'
import { ref,reactive } from 'vue'
import { useRouter } from 'vue-router'
import { getAssetURL } from "../../utils/load_assets"
import { upload } from '../../api/modules/upload'
import { newUpload } from '../../api/modules/upload'
export default {
   


  setup() {
    const router=useRouter()
    const onClickLeft = () => history.back();
    const onClickRight = () => { router.push('talk') };
    const afterRead = (file) => {
      // 此时可以自行将文件上传至服务器
      console.log(file.file);
    let formData = new FormData()
    formData.append('file', file.file)
    newUpload( formData ).then((res) => { console.log(res); })
        // axios({
        //     method: "post",
        //     url: "http://localhost:8081/upload",
        //     data: formData,
        // }).then((result) => {
        //     if(result.code == 200){
        //         console.log("成功"+result);
        //     }else{
        //         console.log("失败");
        //     }
        // }).catch((err) => {
        //     console.log("图片上传失败");
        // });
    };
    const pp = (a,b) => {
        console.log(aa);
        aa.value=a
        bb.value=false
    }
    const pho = () => {
        
    }
    const state = reactive(['p1.png', 'p2.png', 'p3.png'])
    const aa = ref('img.png')
    const bb = ref(true)
    return {
      onClickLeft,
      onClickRight,
      afterRead,
      pp,
      state,
      aa,
      getAssetURL,
      pho,
      bb
    };
  },



};




</script>

<style scoped>
.photo {
    /* width: 390px; */
    height: 300px;
    /* background: url(../../img/img.png) no-repeat center; */
    background-size: 100% 100%; 
}
.photo .cover {
    position: relative;
    width: 390px;
    height: 300px;
}
.photo .cover::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 390px;
    height: 300px;
    background-color: rgba(0, 0, 0, 0.3);
}
.pic {
    margin: 5px;
    display: flex;
}

.pic img {
    width: 85px;
    height: 85px;
    margin: 5px;
}
</style>